
function initPage(baseInfoJson,medicalVentilatorInfo){
	
	$("select:not([data-address])").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
		
	});
	var ICUTypes =  baseInfoJson['ICUTypes'];
	$("select[name$='.icuTypeCode']").each(function(){
		var options = "";
		for(var index in ICUTypes){
			var record = ICUTypes[index];
	    	options+="<option value='"+record.uniq_code+"'>"+record.label+"</option>"
	    }
		$(this).append(options);
	});
	if(medicalVentilatorInfo.isUsedMedicalVentilatorCode){
		$("input[name='isUsedMedicalVentilatorCode'][value='"+medicalVentilatorInfo.isUsedMedicalVentilatorCode+"']").attr("checked",true);
	}
	$("input[name='isUsedMedicalVentilatorCode']").each(function(){
		$(this).dblclick(function(){
			$(this).removeAttr("checked");
		});
	});
	var validator = $("#medicalVentilatorInfoForm").validate({
		errorElement: "title",
		submitHandler:function(form){
			layer.load(1,{offset: '200px'});
			return true;
		},
		rules:{
			
			medicalVentilatorUsedHourNumber: {
            	range:[1,10000]
            }
            
		}
	});
	
	var medicalVentilatorRecords = medicalVentilatorInfo.medicalVentilatorRecords;
	if(medicalVentilatorRecords == undefined || medicalVentilatorRecords.length ==0){
		addMedicalVentilatorRecord();
	}else{
		for(var index in medicalVentilatorRecords){
			var medicalVentilatorRecord = medicalVentilatorRecords[index];
			addMedicalVentilatorRecordByRecord(medicalVentilatorRecord);
	    }
	}
}


function addMedicalVentilatorRecord(){
	var basePath = $("#basePath").val();
	var medicalVentilatorCountOjb = $("#medicalVentilatorRecordCount");
	var count = parseInt(medicalVentilatorCountOjb.val());
	var add_content=$("#template_ventilator_tr").clone();
	add_content.removeAttr("id").removeAttr("hidden");
	
	add_content.find("input[name^='medicalVentilatorRecords[0].']").each(function(){
		var eventObj = $(this);
		eventObj.attr("name",eventObj.attr("name").replace("medicalVentilatorRecords[0]", "medicalVentilatorRecords["+count+"]"));
   		
	});
	
	add_content.find("select[name^='medicalVentilatorRecords[0].']").each(function(){
		var eventObj = $(this);
		eventObj.attr("name",eventObj.attr("name").replace("medicalVentilatorRecords[0]", "medicalVentilatorRecords["+count+"]"));
	});
	
	add_content.find("select").each(function(){
		$(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	$("#medicalVentilatorRecords tbody").append(add_content);
	medicalVentilatorCountOjb.val(count +1);
	return add_content;
}
function addMedicalVentilatorRecordByRecord(record){
	var add_content = addMedicalVentilatorRecord();
	add_content.find("input[name$='.usedStartDateTime']").val(record.usedStartDateTime);
	add_content.find("input[name$='.usedEndDateTime']").val(record.usedEndDateTime);
	if(record.icuTypeCode){
		
		var selectOption = add_content.find("select[name$='.icuTypeCode']").find("option[value='"+record.icuTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			add_content.find("select[name$='.icuTypeCode']").append("<option selected='selected' value='"+infusionBloodRecord.icuTypeCode+"'>"+record.icuTypeName+"</option>");
		}
	}
	
	add_content.find("input[name$='.icuTypeName']").val(record.icuTypeName);
}
function deleteMedicalVentilatorRecord(obj){
	$(obj).parent().parent().remove();
}